package cn.tedu.sp04.feign;

import cn.tedu.sp01.pojo.Item;
import cn.tedu.sp01.util.JsonResult;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 张琪
 * @date 2020/12/22
 * @describe
 */
@Component
public class ItemClientFB implements ItemClient {
    @Override
    public JsonResult<List<Item>> getItems(String orderId) {
//        模拟缓存数据
        if (Math.random() < 0.5) {
            List<Item> list = new ArrayList<>();
            list.add(new Item(4, "商品1", 5));
            list.add(new Item(5, "商品1", 6));
            list.add(new Item(6, "商品1", 2));
            list.add(new Item(7, "商品1", 51));
            list.add(new Item(8, "商品1", 12));

            return JsonResult.ok().data(list);
        }
        return JsonResult.err().msg("获取商品列表失败");
    }

    @Override
    public JsonResult decreaseNumber(List<Item> items) {
        return JsonResult.err().msg("减少商品数量失败");
    }
}
